package com.hm.cms.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.hm.cms.websit.AilabHandler;
import com.hm.cms.websit.Dsj360Handler;
import com.hm.cms.websit.JobboleHandler;
import com.hm.cms.websit.LeiphoneHandler;
import com.hm.cms.websit.TechwebHandler;
import com.hm.cms.websit.WyCtoHandler;
import com.hm.cms.websit.YibaiHandler;
import com.hm.common.util.DateUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * @author shishun.wang
 * @date 2017年12月1日 下午4:03:16
 * @version 1.0
 * @describe 每日任务
 */
@Slf4j
@Component
public class DailyTask {

	@Autowired
	private TaskExecutor taskExecutor;

	@Autowired
	private WyCtoHandler wyCtoHandler;
	
	@Autowired
	private YibaiHandler yibaiHandler;
	
	@Autowired
	private TechwebHandler techwebHandler;
	
	@Autowired
	private LeiphoneHandler leiphoneHandler;
	
	@Autowired
	private AilabHandler ailabHandler;
	
	@Autowired
	private JobboleHandler jobboleHandler;
	
	@Autowired
	private Dsj360Handler dsj360Handler;

	/**
	 * 每天早上1点执行
	 */
	@Scheduled(cron = "0 0 1 * * ?")
	public void wyCtoTask() {
		log.info(DateUtil.now4yyyyMMddhhmm() + "执行51cto数据抓取");
		taskExecutor.execute(new Runnable() {

			@Override
			public void run() {
				wyCtoHandler.handler();
			}
		});
	}
	
	@Scheduled(cron = "0 0 2 * * ?")
	public void yibaiTask() {
		log.info(DateUtil.now4yyyyMMddhhmm() + "执行易百教育数据抓取");
		taskExecutor.execute(new Runnable() {

			@Override
			public void run() {
				yibaiHandler.handler();
			}
		});
	}
	
	@Scheduled(cron = "0 0 3 * * ?")
	public void techwebTask() {
		log.info(DateUtil.now4yyyyMMddhhmm() + "执行techweb数据抓取");
		taskExecutor.execute(new Runnable() {

			@Override
			public void run() {
				techwebHandler.handler();
			}
		});
	}
	
	@Scheduled(cron = "0 0 4 * * ?")
	public void leiphoneTask() {
		log.info(DateUtil.now4yyyyMMddhhmm() + "执行雷锋网数据抓取");
		taskExecutor.execute(new Runnable() {

			@Override
			public void run() {
				leiphoneHandler.handler();
			}
		});
	}
	
	@Scheduled(cron = "0 0 5 * * ?")
	public void jobboleTask() {
		log.info(DateUtil.now4yyyyMMddhhmm() + "执行伯乐在线数据抓取");
		taskExecutor.execute(new Runnable() {

			@Override
			public void run() {
				jobboleHandler.handler();
			}
		});
	}
	
	@Scheduled(cron = "0 0 23 * * ?")
	public void ailabTask() {
		log.info(DateUtil.now4yyyyMMddhhmm() + "执行中国人工智能网数据抓取");
		taskExecutor.execute(new Runnable() {

			@Override
			public void run() {
				ailabHandler.handler();
			}
		});
	}
	
	@Scheduled(cron = "0 0 5 * * ?")
	public void dsj360HandlerTask() {
		log.info(DateUtil.now4yyyyMMddhhmm() + "执行36dj数据抓取");
		taskExecutor.execute(new Runnable() {

			@Override
			public void run() {
				dsj360Handler.handler();
			}
		});
	}
}
